<template>
<div>
	    <!-- 加载 -->
    <div class="example">
        <a-spin size="large" tip="Loading..." :spinning="spinning" />
    </div>
	<div v-if="spinning ==false">
		<a-card>
			<div :class="advanced ? 'search' : null">
			<a-form layout="horizontal" :form="form" @submit="handleSubmit">
				<div :class="advanced ? null: 'fold'">
				<a-row >
				<a-col :md="8" :sm="24" >
					<a-form-item label="计划投放状态" :labelCol="{span: 5}" :wrapperCol="{span: 18, offset: 1}" >
						<a-select v-decorator="['status',]" placeholder="请选择计划操作状态" :allowClear="true">
							<a-select-option value="AD_STATUS_DELIVERY_OK">投放中</a-select-option>
							<a-select-option value="AD_STATUS_DISABLE">计划暂停</a-select-option>
							<a-select-option value="AD_STATUS_AUDIT">新建审核中</a-select-option>
							<a-select-option value="AD_STATUS_REAUDIT">修改审核中</a-select-option>
							<a-select-option value="AD_STATUS_DONE">已完成（投放达到结束时间）</a-select-option>
							<a-select-option value="AD_STATUS_CREATE">计划新建</a-select-option>
							<a-select-option value="AD_STATUS_AUDIT_DENY">审核不通过</a-select-option>
							<a-select-option value="AD_STATUS_BALANCE_EXCEED">账户余额不足</a-select-option>
							<a-select-option value="AD_STATUS_BUDGET_EXCEED">超出预算</a-select-option>
							<a-select-option value="AD_STATUS_NOT_START">未到达投放时间</a-select-option>
							<a-select-option value="AD_STATUS_NO_SCHEDULE">不在投放时段</a-select-option>
							<a-select-option value="AD_STATUS_CAMPAIGN_DISABLE">已被广告组暂停</a-select-option>
							<a-select-option value="AD_STATUS_CAMPAIGN_EXCEED">广告组超出预算</a-select-option>
							<a-select-option value="AD_STATUS_DELETE">已删除</a-select-option>
							<a-select-option value="AD_STATUS_ALL">所有包含已删除</a-select-option>
							<a-select-option value="AD_STATUS_NOT_DELETE">所有不包含已删除（状态过滤默认值）</a-select-option>
						</a-select>
					</a-form-item>
				</a-col>
				<a-col :md="8" :sm="24" >
					<a-form-item
					label="关键词搜索"
					:labelCol="{span: 5}"
					:wrapperCol="{span: 18, offset: 1}"
					>
					<a-input v-decorator="[
						'ad_name',
						]"
				placeholder="请输入名称或ID搜索" />
					</a-form-item>
				</a-col>
				<a-col :md="8" :sm="24" >
					<a-form-item
					label="统计时间范围"
					:labelCol="{span: 5}"
					:wrapperCol="{span: 18, offset: 1}"
					>
						<a-range-picker v-decorator="[
						'ad_create_time',
						]" 
						:disabled-date="disabledDate"
						 />
					</a-form-item>
					
				</a-col>
				</a-row>
				<a-row v-if="advanced">
				
				<a-col :md="8" :sm="24" >
					<a-form-item
					label="计费方式"
					:labelCol="{span: 5}"
					:wrapperCol="{span: 18, offset: 1}"
					>
					<a-select  v-decorator="[
					'pricing',
					]" placeholder="请选择" :allowClear="true">
						<a-select-option value="PRICING_CPC">CPC</a-select-option>
						<a-select-option value="PRICING_CPM">CPM</a-select-option>
						<a-select-option value="PRICING_OCPM">OCPM</a-select-option>
						<a-select-option value="PRICING_CPV">CPV</a-select-option>
						<a-select-option value="PRICING_CPA">CPA</a-select-option>
					</a-select>
					</a-form-item>
				</a-col>

				<a-col :md="8" :sm="24" >
					<a-form-item
					label="投放账户"
					:labelCol="{span: 5}"
					:wrapperCol="{span: 18, offset: 1}"
					>
					<a-select v-decorator="[
						'account_id',
						]" placeholder="请选择投放账户" :allowClear="true">
						<a-select-option v-for="(item,index) in datalist" :key="index" :value="item.account_id">{{item.account_id}}({{item.name}})</a-select-option>
					</a-select>
					</a-form-item>
				</a-col>

				</a-row>
				</div>
				<span style="float: right; margin-top: 3px;">
				<a-button type="primary" @click="queryresult">查询</a-button>
				<a-button @click="btncancel" style="margin-left: 8px">重置</a-button>
				<a @click="toggleAdvanced" style="margin-left: 8px">
					{{advanced ? '收起' : '展开'}}
					<a-icon :type="advanced ? 'up' : 'down'" />
				</a>
				</span>
			</a-form>
			</div>
			<div>
			<div class="operator">
				<a-button @click="addNew" type="primary">新建</a-button>
				<!-- <a-button >批量操作</a-button> -->
				<a-dropdown>
				<a-menu @click="handleMenuClick" slot="overlay">
					<a-menu-item key="enables">启用</a-menu-item>
					<a-menu-item key="suspend">暂停</a-menu-item>
					<a-menu-item key="changeoffer">更改出价</a-menu-item>
					<a-menu-item key="changebudget">更改预算</a-menu-item>
				</a-menu>
				<a-button>
					批量操作 <a-icon type="down" />
				</a-button>
				</a-dropdown>
				<a-button @click="synction"><a-icon type="sync" />同步</a-button>
			</div>

			<a-modal
				title="选择同步广告投放账号"
				:visible="visible"
				:confirm-loading="confirmLoading"
				@ok="handleOk"
				@cancel="handleCancel"
				:width="700"
			>
				<p>说明:同步时间与数量相关,确认后将自动同步,请耐心等待</p>
				<a-input-search placeholder="请输入名称或ID搜索" style="width: 200px;margin-bottom:16px;" @search="onSearch" />

				<a-table :row-selection="rowacountlist" :columns="acountlabel" :scroll="{ x: 210, y: 500 }" :pagination="false" :data-source="datalist">
					<a slot="name" slot-scope="text">{{ text.name }}</a>
				</a-table>
			
			</a-modal>
				<!-- 更改出价 -->
				<a-modal
					title="更改出价"
					:visible="visibleoffer"
					:confirm-loading="confirmLoading"
					@ok="offerOk"
					@cancel="offerCancel"
				>
					<a-form :form="form2">
						<a-form-item
							:wrapperCol="{span: 200}"
							:required="true"
						>
						<a-input-number style="width: 300px" :min="0.1"  placeholder="请输入出价金额" :max="10000" v-decorator="[
								'cpa_bid',
								{ rules: [{ required: true, message: '请输入出价金额，不少于0.1元，不超过10000元' }] } ]" /> &nbsp;元
						</a-form-item>
					</a-form>
				</a-modal>

				<!-- 更改预算-->
				<a-modal
					title="更改预算"
					:visible="visiblebudget"
					:confirm-loading="confirmLoading"
					@ok="budgetOk"
					@cancel="budgetCancel"
				>
					<a-form :form="form3">
						<a-form-item
							:wrapperCol="{span: 200}"
							:required="true"
						>
						<a-input-group compact>
							<a-input-number style="width: 300px" :min="300" placeholder="请输入预算金额" :max="9999999.99" v-decorator="[
							'budget',
							{ rules: [{ required: true, message: '请输入预算金额，不少于300元，不超过9999999.99元' }] } ]" /> &nbsp;元
						</a-input-group>
						</a-form-item>
					</a-form>
				</a-modal>

			<div class="spindiv">
				<a-spin :spinning="spinnings" tip="正在执行，请稍等..." />
			</div>
			<div v-if="spinnings == false">
				<a-table
					:columns="columns"
					:dataSource="dataSource.list"
					:selectedRows.sync="selectedRows"
					@clear="onClear"
					:row-selection="rowSelection"
					:loading='tableloading'
					:pagination="paginationOpt"
					:scroll="{ x: 1500 }"
				>

					<!-- 状态switch -->
					<div slot="switchDemo" slot-scope="text,record,index">
						<a-switch :checked="text.opt_status == 'AD_STATUS_ENABLE' ? true : false" :loading="text.switchloading" @change="onChangedata(text.id,text.account_id,index,$event)" />
					</div>

					<!-- 广告主 -->
					<div slot="mainDemo" slot-scope="text">
						<span>
							{{text.account_id}}
							<p>{{text.ocean_account.name}}</p>
						</span>
					</div>

					<!-- <div slot="optDemo" slot-scope="text">
						<span v-if="text =='AD_STATUS_ENABLE'">启用</span>
						<span v-if="text =='AD_STATUS_DISABLE'">暂停</span>
					</div> -->
					
				<!-- 范围 -->
					<div slot="deliverymode" slot-scope="text">
					<span v-if="text =='UNION'">只投放到资讯联盟（穿山甲）</span>
					<span v-else-if="text == 'UNIVERSAL'">通投智选</span>
					<span v-else>默认</span>
					</div>

			<!-- 内容 -->
					<div slot="promotionDemo" slot-scope="text">
					<span v-if="text =='GOODS'">商品推广</span>
					<span v-else-if="text == 'LIVE'">直播</span>
					<span v-else-if="text == 'AWEME_HOME_PAGE'">抖音主页</span>
					<span v-else-if="text == 'LANDING_PAGE_LINK'">落地页</span>
					<span v-else>不限</span>
					</div>

					<div slot="pricDemo" slot-scope="text">
						<span v-if="text =='PRICING_CPC'">点击付费</span>
						<span v-else-if="text =='PRICING_CPM'">展示付费</span>
						<span v-else-if="text =='PRICING_OCPM'">转化量付费</span>
						<span v-else-if="text =='PRICING_CPV'">出价范围</span>
					</div>

				<!-- 状态 -->
					<div slot="statusDemo" slot-scope="text">
					<span v-if="text =='AD_STATUS_DELIVERY_OK'">投放中</span>
					<span v-else-if="text == 'AD_STATUS_DISABLE'">计划暂停</span>
					<span v-else-if="text == 'AD_STATUS_AUDIT'">新建审核中</span>
					<span v-else-if="text == 'AD_STATUS_REAUDIT'">修改审核中</span>
					<span v-else-if="text == 'AD_STATUS_DONE'">已完成（投放达到结束时间）</span>
					<span v-else-if="text == 'AD_STATUS_CREATE'">计划新建</span>
						<span v-else-if="text == 'AD_STATUS_AUDIT_DENY'">审核不通过</span>
						<span v-else-if="text == 'AD_STATUS_BALANCE_EXCEED'">账户余额不足</span>
						<span v-else-if="text == 'AD_STATUS_BUDGET_EXCEED'">超出预算</span>
						<span v-else-if="text == 'AD_STATUS_NOT_START'">未到达投放时间</span>
						<span v-else-if="text == 'AD_STATUS_NO_SCHEDULE'">不在投放时段</span>
						<span v-else-if="text == 'AD_STATUS_CAMPAIGN_DISABLE'">已被广告组暂停</span>
						<span v-else-if="text == 'AD_STATUS_CAMPAIGN_EXCEED'">广告组超出预算</span>
						<span v-else-if="text == 'AD_STATUS_DELETE'">已删除</span>
						<span v-else-if="text == 'AD_STATUS_ALL'">所有包含已删除</span>
						<span v-else-if="text == 'AD_STATUS_NOT_DELETE'">所有不包含已删除（状态过滤默认值）</span>
					<span v-else>不限</span>
					</div>
					<!-- 深度优化 -->
				<div slot="deepbidDemo" slot-scope="text">
					<span v-if="text =='DEEP_BID_DEFAULT'">无深度优化</span>
					<span v-if="text =='DEEP_BID_PACING'">自动优化</span>
					<span v-if="text =='DEEP_BID_MIN'">自定义双出价</span>
					<span v-if="text =='ROI_COEFFICIENT'">ROI系数</span>
					<span v-if="text =='ROI_PACING'">ROI自动出价</span>
					<span v-if="text =='MIN_SECOND_STAGE'">自定义两阶段</span>
					<span v-if="text =='PACING_SECOND_STAGE'">动态两阶段</span>
					<span v-if="text =='SMARTBID'">自动出价</span>
					<span v-if="text =='AUTO_MIN_SECOND_STAGE'">自动出价两阶段</span>
					<span v-if="text =='BID_PER_ACTION'">每次付费出价</span>
				</div>


				<div slot="action" slot-scope="text">
					<a style="margin-right: 8px" @click="tolink(text)">
						<a-icon type="edit"/>编辑
					</a>
					<p>
					<!-- <a @click="toriginality(text)">
						<a-icon type="ordered-list" />查看创意
					</a> -->
					</p>
					</div>
				</a-table>
			</div>

			</div>
		</a-card>
	</div>
</div>
</template>

<script>
import {ADURL,ADVERPAGE,ACCOUNTURL,SYNCURL,ADUPDATE,ADOFFER} from '@/services/api'
import {ajaxparems,ajaxnoparams} from '@/services/ajaxrequest'
import moment from 'moment';
// import pagination from "@/components/Pagination";
// import { CONSTANTS } from '@antv/data-set';

const columns = [
	{
		title: '',
		width: 60,
		fixed:'left',
		scopedSlots: { customRender: 'switchDemo' }
	},
{
	title: '广告主',
	width:160,
	fixed:'left',
	scopedSlots: { customRender: 'mainDemo' }
  },
  {
	title: '计划名称',
	width:220,
	fixed:'left',
    dataIndex: 'name'
  },
//   {
// 	title: '计划状态',
// 	width:130,
//     dataIndex: 'opt_status',
// 	scopedSlots: { customRender: 'optDemo' }
//   },
{
    title: '投放状态',
	dataIndex: 'status',
	width:130,
	scopedSlots: { customRender: 'statusDemo' }
  },
  {
	title: '广告组ID',
	width:180,
    dataIndex: 'campaign_id'
  },
  {
    title: '投放范围',
	dataIndex: 'delivery_range',
	width:130,
	scopedSlots: { customRender: 'deliverymode' }
  },
  {
    title: '投放内容',
	dataIndex: 'promotion_type',
	width:130,
	scopedSlots: { customRender: 'promotionDemo' }
  },
  {
	title: '付费方式',
	width:130,
	dataIndex: 'pricing',
	scopedSlots: { customRender: 'pricDemo' }
  },
  {
  title: '点击出价/展示出价',
  width:130,
  sorter: (a, b) => a.cpa_bid - b.cpa_bid,
	dataIndex: 'cpa_bid',
  },
  {
	title: '目标转化出价/预期成本',
	width:130,
	sorter: (a, b) => a.budget - b.budget,
	dataIndex: 'budget',
  },
    {
    title: '深度优化方式',
  dataIndex: 'deep_bid_type',
  width:130,
  scopedSlots: { customRender: 'deepbidDemo' }
  },
    {
	title: '消耗',
	width:130,
	sorter: (a, b) => a.cost - b.cost,
    dataIndex: 'cost'
  },
  {
	title: '点击数',
	width:130,
	sorter: (a, b) => a.click - b.click,
    dataIndex: 'click'
  },
    {
	title: '展示数',
	width:130,
	sorter: (a, b) => a.show - b.show,
    dataIndex: 'show'
  }, {
	title: '转化数',
	width:130,
	sorter: (a, b) => a.convert - b.convert,
    dataIndex: 'convert'
  },{
	title: '千次展示成本',
	width:130,
	sorter: (a, b) => a.show_cost - b.show_cost,
    dataIndex: 'show_cost'
  },{
	title: '点击成本',
	width:130,
	sorter: (a, b) => a.click_cost - b.click_cost,
    dataIndex: 'click_cost'
  },
  {
	title: '点击率',
	width:130,
	sorter: (a, b) => a.click_rate - b.click_rate,
    dataIndex: 'click_rate'
  },
  {
	title: '转化成本',
	width:130,
	sorter: (a, b) => a.convert_cost - b.convert_cost,
    dataIndex: 'convert_cost'
  },
   {
	title: '转化率',
	width:130,
	sorter: (a, b) => a.convert_rate - b.convert_rate,
    dataIndex: 'convert_rate'
  },
  
   {
	title: '创建时间',
	width:130,
	dataIndex: 'ad_create_time',
  },
  {
	title: '修改时间',
	width:130,
	dataIndex: 'ad_modify_time',
  },
  {
	title: '操作',
	width:120,
	fixed:'right',
    scopedSlots: { customRender: 'action' }
  },
]

var dataSource = [];
var acountlabel = [
	{
		title:'广告账号',
		scopedSlots: { customRender: 'name' }
	}
]
var datalist =[];

export default {
  name: 'PlansList',
   created(){
	   	this.form = this.$form.createForm(this);
		this.listNew();
		this.accountlist();
	},
	beforeCreate() {
    this.form = this.$form.createForm(this);
    this.form2 = this.$form.createForm(this);
    this.form3 = this.$form.createForm(this);
  },
  inject:['reload'],
  data () {
    return {
		spinning:true,
		advanced: false,
		columns: columns,
		dataSource:dataSource,
		selectedRowslist: [],
		visible:false,
		acountlabel,
		datalist,
		checkaccount:[],
		visibleoffer:false,
		visiblebudget:false,
		spinnings:false,
		switchloading:false,
		tableloading:false,
		paginationOpt: {
			defaultCurrent: 1, // 默认当前页数
			defaultPageSize: 10, // 默认当前页显示数据的大小
			total: 0, // 总数，必须先有
			showSizeChanger: true,
			showQuickJumper: true,
			pageSizeOptions: ["5", "10", "15", "20"],
			showTotal: (total) => `共 ${total} 条`, // 显示总数
			onShowSizeChange: (current, pageSize) => {
				this.paginationOpt.defaultCurrent = 1;
				this.paginationOpt.defaultPageSize = pageSize;
				this.listNew(); //显示列表的接口名称
			},
			// 改变每页数量时更新显示
			onChange: (current, size) => {
				this.paginationOpt.defaultCurrent = current;
				this.paginationOpt.defaultPageSize = size;
				this.listNew();
			},
		},
    }
  },
  authorize: {
    deleteRecord: 'delete'
  },
  methods: {
	  moment,
	  disabledDate(current) {
			//  return time.getTime() > Date.now();
			// return current && current >=moment().subtract(1, "days");
			return current && current >= moment().endOf('day');
		},
	synction(){
		//同步
		this.visible = true;
	},
	handleCancel(){
		// 取消同步
		this.visible = false;
	},
	onSearch(e){
		// 同步账号搜索
		var parems = {"filtering":[
			{"field":'name',"operator":'LIKE',"value":e},
		]};
		ajaxparems(ACCOUNTURL,parems).then((res) => {
			var result=res.data;
			if(result.code =="SUCCESS"){
				this.datalist =result.data;
			}else{
				this.$message.error(result.message, 3)
			}
		})
	},
	handleOk(){
	// 确定同步
		if(this.checkaccount.length <=0){
			this.$message.error("请选择同步账号");
			return;
		}
		var accountlist = [];
		this.checkaccount.forEach((res)=>{
			accountlist.push(res.account_id);
		})
		var parems = {"account_ids":accountlist,"type":'AD'}
		ajaxparems(SYNCURL,parems).then((res) => {
			var result=res.data;
			if(result.code =="SUCCESS"){
				this.visible = false;
				this.$message.success(result.message,3);
				this.reload();
			}else{
				this.$message.error(result.message, 3)
			}
      })
      
	},
    tolink(e){
      var parems = {"id":e.campaign_id};
      ajaxparems(ADVERPAGE, parems).then((res) => {
        var result = res.data;
        if (result.code == "SUCCESS") {
         	this.$router.push({
            	path: '/promotion/advering/editplan/',
				query: {
					campaign_id: e.campaign_id,
					id:e.id,
					modify_time:e.modify_time,
					landing_type:result.data.landing_type
				}
        	})
        } else {
          this.$message.error(result.message, 3);
        }
      });
	},
	toriginality(e){
		//查看创意
		this.$router.push({
			path: '/promotion/advering/originality/',
			query: {
				account_id:e.account_id
			}
		})
	},
    deleteRecord(key) {
      this.dataSource = this.dataSource.filter(item => item.key !== key)
      this.selectedRows = this.selectedRows.filter(item => item.key !== key)
  	},
	btncancel(){
		this.form.resetFields();
		this.listNew();
	},

	queryresult(){
		// 查询条件
		this.paginationOpt.defaultCurrent = 1;
		this.paginationOpt.defaultPageSize = 10;
		this.listNew();
      // var parems = adparems;
	},

	handleSubmit(res){
		console.log(res);
	},
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    remove () {
      this.dataSource = this.dataSource.filter(item => this.selectedRows.findIndex(row => row.key === item.key) === -1)
      this.selectedRows = []
    },
    onClear() {
      this.$message.info('您清空了勾选的所有行')
    },
    onStatusTitleClick() {
      this.$message.info('你点击了状态栏表头')
    },
    onChange() {
      this.$message.info('表格状态改变了')
    },
    // onSelectChange() {
    //   this.$message.info('选中行改变了')
    // },
    addNew () {
		this.$router.push('/promotion/advering/addadver/?tabs=2')
	},
	accountlist(){
		// 获取广告主账号
		ajaxparems(ACCOUNTURL,"").then((res) => {
			var result=res.data;
			if(result.code =="SUCCESS"){
				this.datalist =result.data;
			}else{
				this.$message.error(result.message, 3)
			}
		})
	},

	listNew() {
   	//列表请求
	   this.tableloading = true;
	   const { defaultCurrent, defaultPageSize } = this.paginationOpt;
	   	this.form.validateFieldsAndScroll((err, values) => {
			var parems = {};
			var adparems = [];
			var time =  '';
			var times =  '';
			if(values['status'] !=undefined){
				if(values['status'] =="AD_STATUS_ALL"){
					console.log(1);
				}else if(values['status'] =="AD_STATUS_NOT_DELETE"){
					adparems.push({"field":"status","operator":"NOT_IN","value":['AD_STATUS_DELETE']})
				}else{
					adparems.push({"field":"status","operator":"EQUALS","value":values['status']})
				}
			}
			if(values['ad_name'] !=undefined && values['ad_name'] != ''){
				var numReg = /^[0-9]*$/
				var numRe = new RegExp(numReg)
				if (!numRe.test(values['ad_name'])) {
					adparems.push({"field":"name","operator":"LIKE","value":values['ad_name']})
				}else{
					adparems.push({"field":"id","operator":"LIKE","value":values['ad_name']})
				}
			}

			if(values['ad_create_time'] !=undefined && values['ad_create_time'] !=''){
				time = moment(values['ad_create_time'][0]).format('YYYY-MM-DD')
				times = moment(values['ad_create_time'][1]).format('YYYY-MM-DD')
			}

			if(values['pricing'] !=undefined){
				adparems.push({"field":"pricing","operator":"EQUALS","value":values['pricing']})
			}
			if(values['account_id'] !=undefined){
				adparems.push({"field":"account_id","operator":"EQUALS","value":values['account_id']})
			}

			if(adparems.length >0){
				parems = {
					page:defaultCurrent,
					page_size:defaultPageSize,
					start_date:time,
					end_date:times,
					"filtering":adparems
				};
			}else{
				parems ={
					page:defaultCurrent,
					page_size:defaultPageSize,
					start_date:time,
					end_date:times,
					"filtering":[
					{"field":"status","operator":"NOT_IN","value":["AD_STATUS_DELETE"]}
				]}
			}
			if(time =='' || times ==''){
				this.$delete(parems,'start_date');
				this.$delete(parems,'end_date');
			}

			ajaxparems(ADURL,parems).then((res) => {
				var result=res.data;
				if(result.code =="SUCCESS"){
					result.data.list.map(v=>{
						v.switchloading = false				
					});
					this.paginationOpt.total = result.data.page_info.total;
					this.dataSource = result.data;
					this.tableloading = false;
				}else{
					this.tableloading = false;
					this.$message.error(result.message, 3)
				}
			})

		})
		this.spinning = false;
	},

	//改变状态
	onChangedata(id,account_id,index,e){
		this.dataSource.list[index].switchloading = true;
		//更改广告计划状态
		var parems = {}
		if(e ==true){
			parems = {"advertiser_id":account_id,"ad_ids":[id],"opt_status":'enable'}
		}else{
			parems = {"advertiser_id":account_id,"ad_ids":[id],"opt_status":'disable'}
		}
		ajaxnoparams(account_id, ADUPDATE,parems).then((res) => {
			var result=res.data;
			if(result.code =="SUCCESS"){
				if(e ==true){
					this.dataSource.list[index].opt_status = 'AD_STATUS_ENABLE';
				}else{
					this.dataSource.list[index].opt_status = 'AD_STATUS_DISABLE';
				}
				this.dataSource.list[index].switchloading = false;
				this.$message.success(result.message,3);
				// this.reload();
			}else{
				
				this.$message.error(result.message,3);
			}
		})
	},

	async gatherlist(arrlist,status){
		//数组集合
		let arr = []
		var parems = {};
		arrlist.forEach((res) =>{
			if(arr.indexOf(res.account_id) === -1){
				arr.push(res.account_id)
			}
		})
		for (let i = 0; i < arr.length; i++) {
			let arr2 = []
			arrlist.forEach(ele => {
				if(arr[i] === ele.account_id){
					arr2.push(ele.id)
				}
			});
			parems = {"advertiser_id":arr[i],"ad_ids":arr2,"opt_status":status}
			await ajaxnoparams(arr[i], ADUPDATE,parems).then((res) => {
				var result=res.data;
				if(result.code =="SUCCESS"){
					this.$message.success(arr[i]+result.message,3);
				}else{
					this.$message.error(arr[i]+result.message,3);
				}
			})
		}
		this.spinnings = false;
		this.reload();
		// this.listNew();
	},

    handleMenuClick (e) {
		// 批量操作
		if(this.selectedRowslist.length <=0){
			this.$message.error("请选择广告计划");
			return;
		}
		
		if (e.key === 'enables') {
			this.spinnings = true;
			// 启用
			this.gatherlist(this.selectedRowslist,'enable');
		}else if(e.key ==='suspend'){
			this.spinnings = true;
			// 暂停
			this.gatherlist(this.selectedRowslist,'disable');
		}else if(e.key ==='changeoffer'){
			//修改出价
			this.visibleoffer = true;
		}else if(e.key ==='changebudget'){
			//修改预算
			this.visiblebudget = true;
		}
	},
	offerOk(){
		this.spinnings = true;
		this.confirmLoading = true;
		//确定出价
		 this.form2.validateFieldsAndScroll((err, values) => {
			if(!err){
				let arr = []
				var parems = {};
				this.selectedRowslist.forEach((res) =>{
					if(arr.indexOf(res.account_id) === -1){
						arr.push(res.account_id)
					}
				})
				for (let i = 0; i < arr.length; i++) {
					// let arr2 = []
					this.selectedRowslist.forEach((ele,index) => {
						if(arr[i] === ele.account_id){
							parems = {"advertiser_id":arr[i],"data":[{'ad_id':ele.id,'bid':values['cpa_bid']}]}
							ajaxnoparams(arr[i], ADOFFER,parems).then((res) => {
								var result=res.data;
								if(result.code =="SUCCESS"){
									this.selectedRowslist[index].cpa_bid = values['cpa_bid'];
									this.$message.success(arr[i]+result.message,3);
									this.confirmLoading = false;
									this.spinnings = false;
								}else{
									this.spinnings = false;
									this.$message.error(arr[i]+result.message,3);
									this.confirmLoading = false;
								}
							})
						}

					});	
				}
			}
		 })
		this.visibleoffer = false;
		this.reload();
	},
	offerCancel(){
		//取消出价
		this.visibleoffer = false;
	},
	budgetOk(){
		//确定预算
		this.spinnings = true;
		 this.form3.validateFieldsAndScroll((err, values) => {
			if(!err){
				if(!err){
				let arr = []
				var parems = {};

				this.selectedRowslist.forEach((res) =>{
					if(arr.indexOf(res.account_id) === -1){
						arr.push(res.account_id)
					}
				})
				for (let i = 0; i < arr.length; i++) {
					// let arr2 = []
					this.selectedRowslist.forEach((ele,index) => {
						if(arr[i] === ele.account_id){
							parems = {"advertiser_id":arr[i],"data":[{'ad_id':ele.id,'bid':values['budget']}]}
							ajaxnoparams(arr[i], ADOFFER,parems).then((res) => {
								var result=res.data;
								if(result.code =="SUCCESS"){
									this.selectedRowslist[index].budget = values['budget'];
									this.$message.success(arr[i]+result.message,3);
									this.confirmLoading = false;
									this.spinnings = false;
								}else{
									this.$message.error(arr[i]+result.message,3);
									this.confirmLoading = false;
									this.spinnings = false;
								}
							})
						}
					});	
				}
			}
			}
		 })
		this.visiblebudget = false;
		this.reload();
	},
	budgetCancel(){
    //取消预算
		this.visiblebudget = false;
	},

  },computed: {
    rowSelection() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
			this.selectedRowslist = selectedRows;
        //   console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
        },
      };
	},
	rowacountlist() {
      return {
        onChange: (selectedRowKeys, selectedRows) => {
		//   console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
			this.checkaccount = selectedRows;
        },
      };
    }
  }
}
</script>

<style lang="less" scoped>
  .example {
    text-align: center;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
    margin-bottom: 20px;
    /* padding: 30px 50px; */
    margin: 20px 0;
  }
  .search{
    margin-bottom: 54px;
  }
  .fold{
    width: calc(100% - 216px);
    display: inline-block
  }
  .operator{
    margin-bottom: 18px;
  }
  @media screen and (max-width: 900px) {
    .fold {
      width: 100%;
    }
  }
</style>
